package cn.cyh.queue_service.websocket;

import cn.cyh.queue_service.model.dto.QueueStatusResponse;
import cn.cyh.queue_service.model.entity.Queue;
import cn.cyh.queue_service.model.entity.ServiceType;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

/**
 * 业务队列
 *
 * @author xujunwen
 * @since 2025-04-10 09:01
 **/
@Data
@Slf4j
public class CurrentQueues {

    public static Map<String , WebSocketSession> sessionMap = new HashMap<>();

    public static void sendRefreshData() {
        SocketMsg msg = new SocketMsg();
        msg.setType("reFreshData");
        msg.setData(Boolean.TRUE);
        sessionMap.values().forEach(session -> {
            try {
                if (session.isOpen()) {
                    session.sendMessage(new TextMessage(JSONUtil.toJsonStr(msg)));
                }
            } catch (IOException e) {
                log.error("发送消息时发生错误: {}", e.getMessage(), e);
            }
        });
    }

}
